package com.xr.sy.modules.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xr.common.service.impl.CrudServiceImpl;
import com.xr.common.utils.ConvertUtils;
import com.xr.sy.modules.business.dao.SysMessageDao;
import com.xr.sy.modules.business.dto.SysMessageDTO;
import com.xr.sy.modules.business.entity.SysMessageEntity;
import com.xr.sy.modules.business.service.SysMessageService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 清单
 *
 * @author Joe 825525632@qq.com
 * @since 1.0.0 2019-11-26
 */
@Service
public class SysMessageServiceImpl extends CrudServiceImpl<SysMessageDao, SysMessageEntity, SysMessageDTO> implements SysMessageService {

    @Override
    public QueryWrapper<SysMessageEntity> getWrapper(Map<String, Object> params) {
        String type = (String) params.get("type");
        String name = (String) params.get("name");

        QueryWrapper<SysMessageEntity> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(type), "type", type);
        wrapper.like(StringUtils.isNotBlank(name), "name", name);
        wrapper.orderByAsc("no");

        return wrapper;
    }

    @Override
    public List<SysMessageDTO> list(Map<String, Object> params) {
        List<SysMessageEntity> list = baseDao.selectList(getWrapper(params));
        return ConvertUtils.sourceToTarget(list, SysMessageDTO.class);
    }
}